/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Registro.java
 *
 * Created on 6/05/2009, 11:04:41 PM
 */
package gui;

import Multimedia.MediaSonido;
import conexion.RmiCliente;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javazoom.jlgui.basicplayer.BasicPlayerException;
//import org.jvnet.substance.SubstanceLookAndFeel;
//import org.jvnet.substance.watermark.SubstanceImageWatermark;

/**
 *
 * @author arquitectura
 */
public class Home extends javax.swing.JFrame {

    private RmiCliente rc;
    private VerPerfilJugador pj;
    private MenuPerfil mp;
    private String Usuario;
    private Estadisticas Est;
    public  MediaSonido sonidoLogin;

    /** Creates new form Registro */
    public Home(){
        initComponents();
        xPnlFondo pnlFondo = new xPnlFondo(5);
        this.add(pnlFondo);
        this.pack();
    }

    public Home(String usuario, Login in, MediaSonido sonidoLoginEntrada,String ip) {
        initComponents();

        sonidoLogin = sonidoLoginEntrada;
        xPnlFondo pnlFondo = new xPnlFondo(5);
        this.add(pnlFondo);
        this.pack();

        this.setSize(800, 625);

        this.setLocationRelativeTo(null);
        this.Usuario = usuario;
        this.rc = new RmiCliente(ip);
        this.rc.conectarseAlServidor(this, in);


        MediaSonido testca = new MediaSonido();
        try {
            sonidoLogin.stop();
            sonidoLogin.loadFile("C:/Documents and Settings/Arquitectura/Escritorio/song02.mp3");
            sonidoLogin.play();

        } catch (BasicPlayerException ex) {
            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
        }

        this.enviar();

    }

    public RmiCliente getRc() {
        return rc;
    }

    public void setRc(RmiCliente rc) {
        this.rc = rc;
    }

    public void enviar() {

        this.rc.enviarMensaje(this.Usuario);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BTN_salir = new javax.swing.JButton();
        jbEnviar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtChatEnviar = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtChatMostrar = new javax.swing.JTextArea();
        ContenedorMenu = new javax.swing.JPanel();
        BTN_perfil = new javax.swing.JButton();
        BTN_partida = new javax.swing.JButton();
        BTN_estadisticas = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Home");
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setForeground(java.awt.Color.white);
        setMinimumSize(new java.awt.Dimension(800, 625));
        setResizable(false);
        setUndecorated(true);

        BTN_salir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar.png"))); // NOI18N
        BTN_salir.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        BTN_salir.setBorderPainted(false);
        BTN_salir.setContentAreaFilled(false);
        BTN_salir.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar_roll.png"))); // NOI18N
        BTN_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_salirActionPerformed(evt);
            }
        });

        jbEnviar.setText("Enviar");
        jbEnviar.setOpaque(false);
        jbEnviar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEnviarActionPerformed(evt);
            }
        });

        jtChatEnviar.setColumns(20);
        jtChatEnviar.setRows(5);
        jtChatEnviar.setOpaque(false);
        jScrollPane1.setViewportView(jtChatEnviar);

        jtChatMostrar.setColumns(20);
        jtChatMostrar.setRows(5);
        jtChatMostrar.setBorder(null);
        jtChatMostrar.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jtChatMostrar.setOpaque(false);
        jScrollPane2.setViewportView(jtChatMostrar);

        ContenedorMenu.setOpaque(false);
        ContenedorMenu.setPreferredSize(new java.awt.Dimension(800, 100));

        BTN_perfil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mperfil.png"))); // NOI18N
        BTN_perfil.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        BTN_perfil.setBorderPainted(false);
        BTN_perfil.setContentAreaFilled(false);
        BTN_perfil.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mperfil_roll.png"))); // NOI18N
        BTN_perfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_perfilActionPerformed(evt);
            }
        });

        BTN_partida.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mpartida.png"))); // NOI18N
        BTN_partida.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        BTN_partida.setBorderPainted(false);
        BTN_partida.setContentAreaFilled(false);
        BTN_partida.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mpartida_roll.png"))); // NOI18N
        BTN_partida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_partidaActionPerformed(evt);
            }
        });

        BTN_estadisticas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mestadisticas .png"))); // NOI18N
        BTN_estadisticas.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        BTN_estadisticas.setBorderPainted(false);
        BTN_estadisticas.setContentAreaFilled(false);
        BTN_estadisticas.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mestadisticas_roll.png"))); // NOI18N
        BTN_estadisticas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_estadisticasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ContenedorMenuLayout = new javax.swing.GroupLayout(ContenedorMenu);
        ContenedorMenu.setLayout(ContenedorMenuLayout);
        ContenedorMenuLayout.setHorizontalGroup(
            ContenedorMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ContenedorMenuLayout.createSequentialGroup()
                .addContainerGap(168, Short.MAX_VALUE)
                .addComponent(BTN_partida)
                .addGap(38, 38, 38)
                .addComponent(BTN_perfil)
                .addGap(32, 32, 32)
                .addComponent(BTN_estadisticas)
                .addGap(77, 77, 77))
        );
        ContenedorMenuLayout.setVerticalGroup(
            ContenedorMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ContenedorMenuLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ContenedorMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(BTN_partida)
                    .addComponent(BTN_perfil)
                    .addComponent(BTN_estadisticas))
                .addContainerGap(48, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(159, 159, 159)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 481, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbEnviar, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                        .addContainerGap(160, Short.MAX_VALUE))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(725, Short.MAX_VALUE)
                .addComponent(BTN_salir, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34))
            .addComponent(ContenedorMenu, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(BTN_salir, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(111, 111, 111)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jbEnviar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
                .addComponent(ContenedorMenu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-600)/2, 800, 600);
    }// </editor-fold>//GEN-END:initComponents
    private void BTN_partidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_partidaActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        MenuPartida mp  = new MenuPartida(this, this.Usuario,sonidoLogin);
        //CrearPartida cp = new CrearPartida(this, this.Usuario, sonidoLogin);
        JFrame.setDefaultLookAndFeelDecorated(true);

        //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        //SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");//Ejemplo de aplicacion de un watermark de Substance
        //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark("http://72.29.81.246/~imindjav/images/CrearPartida.jpg"));
        //SubstanceLookAndFeel.setImageWatermarkOpacity(new Float(1));
        
        mp.setVisible(true);
        //cp.setVisible(true);
    }//GEN-LAST:event_BTN_partidaActionPerformed

    private void BTN_perfilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_perfilActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        mp = new MenuPerfil(Usuario,this);
        //pj = new VerPerfilJugador(Usuario, this);
        //JFrame.setDefaultLookAndFeelDecorated(true);

        //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        //SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");//Ejemplo de aplicacion de un watermark de Substance
        //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark("http://72.29.81.246/~imindjav/images/VerPerfilAdmin.jpg"));
        //SubstanceLookAndFeel.setImageWatermarkOpacity(new Float(1));
        mp.setVisible(true);
        //pj.setVisible(true);
    }//GEN-LAST:event_BTN_perfilActionPerformed

    private void BTN_estadisticasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_estadisticasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);

        //JFrame.setDefaultLookAndFeelDecorated(true);
        //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        //SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");//Ejemplo de aplicacion de un watermark de Substance
        //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark("http://72.29.81.246/~imindjav/images/Estadisticas.jpg"));
        //SubstanceLookAndFeel.setImageWatermarkOpacity(new Float(1));

        Est = new Estadisticas(Usuario, rc, this);
        Est.setVisible(true);
    //public Estadisticas(String usuario, RmiCliente rc, guiCliente gc)

    }//GEN-LAST:event_BTN_estadisticasActionPerformed

    private void BTN_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_salirActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        this.rc.salirSistema(this.Usuario);
        this.rc.salir(this);
    }//GEN-LAST:event_BTN_salirActionPerformed

    private void jbEnviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEnviarActionPerformed
        // TODO add your handling code here:

        String men = this.rc.nuevomsg(this.Usuario, this.jtChatEnviar.getText());
        System.out.println(men);
        //String aux = this.Usuario + ": "+ this.jtChatEnviar.getText();
        if (men.equals("nada")) {
        } else {
            this.jtChatMostrar.setText(men + "\n");
            this.jtChatEnviar.setText(""); //para dejar la caja de envio de msn en blanco            
        }

    }//GEN-LAST:event_jbEnviarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        //JFrame.setDefaultLookAndFeelDecorated(true);
        //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        //SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");//Ejemplo de aplicacion de un watermark de Substance
        //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark("http://72.29.81.246/~imindjav/images/Home.jpg"));
        //SubstanceLookAndFeel.setImageWatermarkOpacity(new Float(1));
    
        java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
        new Home().setVisible(true);
        }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTN_estadisticas;
    private javax.swing.JButton BTN_partida;
    private javax.swing.JButton BTN_perfil;
    private javax.swing.JButton BTN_salir;
    private javax.swing.JPanel ContenedorMenu;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbEnviar;
    private javax.swing.JTextArea jtChatEnviar;
    private javax.swing.JTextArea jtChatMostrar;
    // End of variables declaration//GEN-END:variables
}
